package com.hs.task.quartz;


import com.hs.task.po.EisdPo;
import com.hs.task.util.ExcelFileUtil;
import com.hs.task.util.HttpRequestUtils;
import com.hs.task.util.JsonDateValueProcessor;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.DefaultValueProcessor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;
import java.io.FileFilter;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by chenyq5 on 2016-6-1.
 */
@Controller
@RequestMapping("/eisd")
@Component("eisdTask")
public class EisdTask {

    @Value("${uploadEisdUrl}")
    private String uploadURL;

    @Value("${getbyPatIdUrl}")
    private String getbyPatIdURL;

    @Value("${newPath}")
    private String newPath;

    @Value("${oldPath}")
    private String oldPath;


    @RequestMapping("upload")
    @ResponseBody
    //  @Scheduled(cron="0 * * * * *")
    public Map<String, Object> execute() {
        Map<String, Object> resultMap = process();
        return resultMap;
    }

    public Map<String, Object> process() {
        Date today = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd");
        String[] todayStr = format.format(today).split("-");
        String year = todayStr[0];
        String month = todayStr[1];
        String day = todayStr[2];

        List<String> fileList = new ArrayList<String>();
        //处理新版本
        {
            String todayDir = newPath + "/" + year + "/" + month + "/" + day;
            File todayPah = new File(todayDir);
            if (todayPah.exists()) {
                fileList = getFileName(todayDir);
            }
        }
        //处理旧版本
        String todayDir = year + month + day;
        File rootPath = new File(oldPath);
        if (rootPath.exists()) {
            File[] dirs = rootPath.listFiles();
            for (File d : dirs) {
                if (d.isDirectory()) {
                    String name = d.getName();
                    String dataStr = name.split("_")[0];
                    if (dataStr.equals(todayDir)) {
                        fileList = getFileName(d.getAbsolutePath());
                    }
                }
            }
        }

        int mark = 0;
        Map<String, Object> reslutMap = new HashMap<String, Object>();
        List<String> failedList = new ArrayList<>();
        for (String file : fileList) {
            System.out.println(file);
            try {
                mark = uploadExcelData(file);
            } catch (Exception e) {
                failedList.add(file);
                mark = -1;
                e.printStackTrace();
            }
        }
        reslutMap.put("mark", mark);
        reslutMap.put("failedList", failedList);
        return reslutMap;

    }


    //获取目录下的xls和xlsx文件名
    public List<String> getFileName(String path) {
        File dir = new File(path);
        List<String> fileList = new ArrayList<String>();
        if (!dir.exists()) {
            return fileList;
        }
        if (dir.isDirectory()) {
            File[] files = dir.listFiles(getXlsfile);
            for (File file : files) {
                fileList.add(file.getAbsolutePath());
            }
        } else {
            fileList.add(path);
        }
        return fileList;
    }

    FileFilter getXlsfile = new FileFilter() {
        public boolean accept(File pathName) {
            if ((pathName.toString().endsWith("xls") || pathName.toString().endsWith("xlsx") && (!pathName.toString().contains("~$")))) {
                return true;
            } else {
                return false;
            }

        }
    };

    public int uploadExcelData(String fileName) throws Exception {
        boolean result = true;
        Workbook wb = null;
        Sheet sheet = null;
        // EisdDataModel eisdPo = new EisdDataModel();
        EisdPo eisdPo = new EisdPo();
        wb = ExcelFileUtil.readExcel(fileName);
        sheet = wb.getSheetAt(0);        //获得第一个表单
        Iterator<Row> rows = sheet.rowIterator();    //获得第一个表单的迭代器
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String patient_id = null;
        String patient_name = null;
        String check_date = null;
        while (rows.hasNext()) {
            Row row = rows.next();    //获得行数据
            int rowRum = row.getRowNum();
            if (row.getCell(0) == null) {
                break;
            }
            String attr = row.getCell(0).toString().trim();
            switch (attr) {
                case "HOSPITAL NAME":
                case "医院名称":
                    eisdPo.setHospital((String) ExcelFileUtil.getCellValue(row.getCell(1)));
                    break;
                case "Clinic Code":
                case "诊所码":
                    eisdPo.setHospital_code((String) ExcelFileUtil.getCellValue(row.getCell(1)));
                    break;
                case "Doctor ID":
                case "医生ID":
                    eisdPo.setDoctor_id((String) ExcelFileUtil.getCellValue(row.getCell(1)));
                    break;
                case "Patient ID":
                case "病人ID": {
                    patient_id = (String) ExcelFileUtil.getCellValue(row.getCell(1));
                    eisdPo.setPatient_id((String) ExcelFileUtil.getCellValue(row.getCell(1)));
                    break;
                }
                case "Patient Name":
                case "患者姓名": {
                    patient_name = (String) ExcelFileUtil.getCellValue(row.getCell(1));
                    eisdPo.setPatient_name((String) ExcelFileUtil.getCellValue(row.getCell(1)));
                    break;
                }
                case "Weight":
                case "重量": {
                    String cellValue = (String) ExcelFileUtil.getCellValue(row.getCell(1));
                    String weight = cellValue.substring(0, cellValue.indexOf("Kg") - 1);
                    eisdPo.setWeight(Double.parseDouble(weight));
                    break;
                }
                case "Height":
                case "身高":
                    eisdPo.setHeight(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    break;
                case "Gender":
                case "性别":
                    eisdPo.setSex((String) ExcelFileUtil.getCellValue(row.getCell(1)));
                    break;
                case "Date of birth":
                case "出生日期": {
                    String dateStr = (String) ExcelFileUtil.getCellValue(row.getCell(1));
                    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
                    Date date = sdf.parse(dateStr);
                    eisdPo.setBirth_date(date);
                    break;
                }
                case "Date of Detection":
                case "检测日期": {
                    String dateStr = ExcelFileUtil.getCellValue(row.getCell(1)) + " " + ExcelFileUtil.getCellValue(row.getCell(2));
                    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
                    Date date = sdf.parse(dateStr);
                    SimpleDateFormat ymd = new SimpleDateFormat("yyyy/MM/dd HH:mm");
                    check_date = ymd.format(date);
                    eisdPo.setCheck_date(date);
                    break;
                }
                case "Index of Weight":
                case "体重指数":
                    eisdPo.setBmi(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    break;
                case "Age":
                case "年龄":
                    eisdPo.setAge(Integer.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    break;
                //获取检测结果指标行数
                case "自主神经系统功能障碍:":
                case "ANSD:": {
                    if (resultMap.get("ansd") == null || (row.getRowNum() < (int) resultMap.get("ansd"))) {
                        resultMap.put("ansd", row.getRowNum());
                        resultMap.put("自主神经系统功能障碍:", row.getRowNum());
                    }
                    break;
                }
                case "排汗系统功能障碍:":
                case "SudoD:": {
                    if (resultMap.get("sudod") == null || (row.getRowNum() < (int) resultMap.get("sudod"))) {
                        resultMap.put("sudod", row.getRowNum());
                    }
                    break;
                }
                case "内皮功能障碍:":
                case "EndoD:": {
                    if (resultMap.get("endod") == null || (row.getRowNum() < (int) resultMap.get("endod"))) {
                        resultMap.put("endod", row.getRowNum());
                    }
                    break;
                }
                case "心血管代谢风险:":
                case "CMR:": {
                    if (resultMap.get("cmr") == null || (row.getRowNum() < (int) resultMap.get("cmr"))) {
                        resultMap.put("cmr", row.getRowNum());
                    }
                    break;
                }
                case "糖耐量受损:":
                case "IGT:": {
                    if (resultMap.get("igt") == null || (row.getRowNum() < (int) resultMap.get("igt"))) {
                        resultMap.put("igt", row.getRowNum());
                    }
                    break;
                }
                case "周围远端神经病变:":
                case "PDN:": {
                    if (resultMap.get("pdn") == null || (row.getRowNum() < (int) resultMap.get("pdn"))) {
                        resultMap.put("pdn", row.getRowNum());
                    }
                    break;
                }
                case "心脏自主神经病变:":
                case "CAN:": {
                    if (resultMap.get("can") == null || (row.getRowNum() < (int) resultMap.get("can"))) {
                        resultMap.put("can", row.getRowNum());
                    }
                    break;
                }
                case "冠状动脉疾病 :":
                case "CAD:": {
                    if (resultMap.get("cad") == null || (row.getRowNum() < (int) resultMap.get("cad"))) {
                        resultMap.put("cad", row.getRowNum());
                    }
                    break;
                }
                //排汗反应（SMR）分析（足部皮肤微循环评分）
                case "Sudomotor Comments":
                case "排汗解释":
                    resultMap.put("排汗解释", row.getRowNum());
                    break;
                case "Sympathetic Response Markers":
                case "内皮细胞":
                    resultMap.put("内皮细胞", row.getRowNum());
                    break;

                case "ESRNO":
                case "一氧化氮皮肤电反应": {
                    int kindNum;
                    if (resultMap.get("内皮细胞") != null) {
                        kindNum = (int) resultMap.get("内皮细胞");
                    } else {
                        break;
                    }
                    if (rowRum == (kindNum + 2)) {
                        eisdPo.setEsr_no_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setEsr_no_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }
                case "ESRCL": {
                    eisdPo.setEsr_cl_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    break;
                }

                case "ESRCl": {
                    eisdPo.setEsr_cl_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    break;
                }

                case "sudomotor dysfunction score":
                case "排汗功能障碍评分":
                    resultMap.put("排汗功能障碍评分", row.getRowNum());
                    break;

                case "Peak C":
                case "峰值电导":
                    eisdPo.setCon_peak_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    break;
                case "Peak C.":
                    eisdPo.setCon_peak_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    break;

                //自主神经系统(ANS)测试分析（心血管病变风险评分）
                case "Parasympathetic risk value":
                case "副交感神经风险值": {
                    resultMap.put("副交感神经风险值", row.getRowNum());
                    Row eirRow = sheet.getRow(rowRum + 2);
                    Row valsRow = sheet.getRow(rowRum + 3);
                    Row k3015Row = sheet.getRow(rowRum + 4);
                    if (eirRow.getCell(0).toString().trim().equals("E/I R")) {
                        eisdPo.setEi_r_value(Double.valueOf(eirRow.getCell(3).toString()));
                    }
                    if (valsRow.getCell(0).toString().trim().equals("Vals.R") || valsRow.getCell(0).toString().trim().equals("瓦氏比率")) {
                        eisdPo.setVals_r_value(Double.valueOf(valsRow.getCell(3).toString()));
                    }
                    if (k3015Row.getCell(0).toString().trim().equals("K3015")) {
                        eisdPo.setK3015_value(Double.valueOf(k3015Row.getCell(3).toString()));
                    }
                }
                break;

                case "Parasympathetic Risk Score": {
                    Row eirRow = sheet.getRow(rowRum + 1);
                    Row valsRow = sheet.getRow(rowRum + 2);
                    Row k3015Row = sheet.getRow(rowRum + 3);
                    if (eirRow.getCell(0).toString().trim().equals("E/I R")) {
                        eisdPo.setEi_r_score(Double.valueOf(eirRow.getCell(1).toString()));
                    }
                    if (valsRow.getCell(0).toString().trim().equals("Vals.R")) {
                        eisdPo.setVals_r_score(Double.valueOf(valsRow.getCell(1).toString()));

                    }
                    if (k3015Row.getCell(0).toString().trim().equals("K3015")) {
                        eisdPo.setK3015_score(Double.valueOf(k3015Row.getCell(1).toString()));
                    }
                }
                break;


                case "Sympathetic response marker": {
                    Row sprsRow = sheet.getRow(rowRum + 1);
                    Row sprv2Row = sheet.getRow(rowRum + 2);
                    Row dprsRow = sheet.getRow(rowRum + 3);
                    if (sprsRow.getCell(0).toString().trim().equals("SPRS")) {
                        eisdPo.setSprs_score(Double.valueOf(sprsRow.getCell(1).toString()));
                    }
                    if (sprv2Row.getCell(0).toString().trim().equals("SPRV2")) {
                        eisdPo.setSprv2_score(Double.valueOf(sprv2Row.getCell(1).toString()));
                    }
                    if (dprsRow.getCell(0).toString().trim().equals("DPRS")) {
                        eisdPo.setDprs_score(Double.valueOf(dprsRow.getCell(1).toString()));
                    }
                }
                break;

                case "站立收缩压":
                    eisdPo.setSprs_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    break;

                case "瓦氏二段收缩压":
                    eisdPo.setSprv2_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    break;

                case "站立舒张压":
                    eisdPo.setDprs_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    break;

                case "STA Score":
                    eisdPo.setSta_score((String) ExcelFileUtil.getCellValue(row.getCell(1)));
                    break;

                case "PTF Score":
                case "副交感神经检测评分":
                    eisdPo.setP_risk_score((String) ExcelFileUtil.getCellValue(row.getCell(1)));
                    break;

                //心率变异性（HRV）分析报告
                case "autonomic nervous system activity value":
                case "自主神经系统活性值":
                    resultMap.put(attr, row.getRowNum());
                    break;

                case "SDNN":
                case "心率变异标准差": {
                    int kindNum;
                    if (resultMap.get("自主神经系统活性值") != null) {
                        kindNum = (int) resultMap.get("自主神经系统活性值");
                    } else if (resultMap.get("autonomic nervous system activity value") != null) {
                        kindNum = (int) resultMap.get("autonomic nervous system activity value");
                    } else {
                        break;
                    }
                    if (rowRum == (kindNum + 2)) {
                        eisdPo.setHrv_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setHrv_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }
                case "RMSSD":
                case "连续性差异平方根": {
                    int kindNum;
                    if (resultMap.get("自主神经系统活性值") != null) {
                        kindNum = (int) resultMap.get("自主神经系统活性值");
                    } else if (resultMap.get("autonomic nervous system activity value") != null) {
                        kindNum = (int) resultMap.get("autonomic nervous system activity value");
                    } else {
                        break;
                    }
                    if (rowRum == (kindNum + 3)) {
                        eisdPo.setRmssd_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setRmssd_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }
                case "TP": {
                    int kindNum;
                    if (resultMap.get("自主神经系统活性值") != null) {
                        kindNum = (int) resultMap.get("自主神经系统活性值");
                    } else if (resultMap.get("autonomic nervous system activity value") != null) {
                        kindNum = (int) resultMap.get("autonomic nervous system activity value");
                    } else {
                        break;
                    }
                    if (rowRum == (kindNum + 4)) {
                        eisdPo.setTp_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setTp_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }

                //自主神经系统平衡值
                case "autonomic nervous system balance value":
                case "自主神经系统平衡值":
                    resultMap.put(attr, row.getRowNum());
                    break;

                case "Stress.I":
                case "压力指数": {
                    int kindNum;
                    if (resultMap.get("自主神经系统平衡值") != null) {
                        kindNum = (int) resultMap.get("自主神经系统平衡值");
                    } else if (resultMap.get("autonomic nervous system balance value") != null) {
                        kindNum = (int) resultMap.get("autonomic nervous system balance value");
                    } else {
                        break;
                    }
                    if (rowRum == (kindNum + 2)) {
                        eisdPo.setPsi_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setPsi_socre(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }

                case "HF":
                case "高频": {
                    int kindNum;
                    if (resultMap.get("自主神经系统平衡值") != null) {
                        kindNum = (int) resultMap.get("自主神经系统平衡值");
                    } else if (resultMap.get("autonomic nervous system balance value") != null) {
                        kindNum = (int) resultMap.get("autonomic nervous system balance value");
                    } else {
                        break;
                    }
                    if (rowRum == (kindNum + 3)) {
                        eisdPo.setHf_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setHf_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }

                case "LF/HF":
                case "低频/高频": {
                    int kindNum;
                    if (resultMap.get("自主神经系统平衡值") != null) {
                        kindNum = (int) resultMap.get("自主神经系统平衡值");
                    } else if (resultMap.get("autonomic nervous system balance value") != null) {
                        kindNum = (int) resultMap.get("autonomic nervous system balance value");
                    } else {
                        break;
                    }
                    if (rowRum == (kindNum + 4)) {
                        eisdPo.setLf_hf_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setLf_hf_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }

                //自主神经系统活性评分
                case "ANSa Score":
                case "自主神经系统活性评分":
                    resultMap.put("自主神经系统活性评分", row.getRowNum());
                    break;

                //自主神经系统平衡评分
                case "ANSb Score":
                case "自主神经系统平衡评分":
                    resultMap.put("自主神经系统平衡评分", row.getRowNum());
                    break;

                //内稳态紊乱值
                case "Homeostasis Dysfunction value":
                case "内稳态紊乱值":
                    resultMap.put("内稳态紊乱值", row.getRowNum());
                    break;

                case "PTGVLFi":
                case "光电容积极低频指数": {
                    int kindNum;
                    if (resultMap.get("内稳态紊乱值") != null) {
                        kindNum = (int) resultMap.get("内稳态紊乱值");
                    } else {
                        break;
                    }
                    if (rowRum == (kindNum + 2)) {
                        eisdPo.setPpg_lf_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setPpg_lf_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }

                case "PTG I":
                case "光电容积描记指数": {
                    int kindNum;
                    if (resultMap.get("内稳态紊乱值") != null) {
                        kindNum = (int) resultMap.get("内稳态紊乱值");
                    } else {
                        break;
                    }
                    if (rowRum == (kindNum + 3)) {
                        eisdPo.setPpg_index_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setPpg_index_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }

                case "PTG R":
                case "光电容积描记比值": {
                    int kindNum;
                    if (resultMap.get("内稳态紊乱值") != null) {
                        kindNum = (int) resultMap.get("内稳态紊乱值");
                    } else {
                        break;
                    }
                    if (rowRum == (kindNum + 4)) {
                        eisdPo.setPpg_rate_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setPpg_rate_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }

                //Endothelial Dysfunction value

                case "Endothelial Dysfunction value":
                    resultMap.put(attr, row.getRowNum());
                    break;

                case "RI":
                case "反射指数": {
                    int kindNum = (int) resultMap.get("Endothelial Dysfunction value");
                    if (rowRum == (kindNum + 2)) {
                        eisdPo.setRi_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setRi_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }


                case "SDda":
                    eisdPo.setSdda_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    break;
                case "SDba": {
                    eisdPo.setSdba_value(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    break;
                }

                //内稳态评分
                case "Homeo Score":
                case "内稳态评分":
                    resultMap.put("内稳态评分", row.getRowNum());
                    break;

                //内皮检测评分
                case "-SD da":
                case "小动脉狭窄指标":
                    eisdPo.setSdda_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    break;

                case "SD ba":
                case "检测点间比率":
                    eisdPo.setSdba_score(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    break;

                case "EndoT Score":
                case "内皮检测评分":
                    resultMap.put("内皮检测评分", row.getRowNum());
                    break;

                //生命体征检测值
                case "Heart Rate":
                case "心率": {
                    if (eisdPo.getHeart_rate() == null) {
                        eisdPo.setHeart_rate(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(1))));
                    }
                    break;
                }
                case "SpO2":
                    eisdPo.setSpo2(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    break;
                case "Systolic PB": {
                    if (ExcelFileUtil.getCellValue(row.getCell(3)) != null && (!ExcelFileUtil.getCellValue(row.getCell(3)).equals(""))) {
                        eisdPo.setSystolic_pb(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setSystolic_pb((double) 0);
                    }
                    break;
                }
                case "Diastolic PB": {
                    if (ExcelFileUtil.getCellValue(row.getCell(3)) != null && (!ExcelFileUtil.getCellValue(row.getCell(3)).equals(""))) {
                        eisdPo.setDiastolic_pb(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setDiastolic_pb((double) 0);
                    }
                    break;
                }
                case "Systolic PV": {
                    if (ExcelFileUtil.getCellValue(row.getCell(3)) != null && (!ExcelFileUtil.getCellValue(row.getCell(3)).equals(""))) {
                        eisdPo.setSystolic_pv(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setSystolic_pv((double) 0);
                    }
                    break;
                }
                case "Diastolic PV": {
                    if (ExcelFileUtil.getCellValue(row.getCell(3)) != null && (!ExcelFileUtil.getCellValue(row.getCell(3)).equals(""))) {
                        eisdPo.setDiastolic_pv(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setDiastolic_pv((double) 0);
                    }
                    break;
                }
                case "Systolic PS": {
                    Object cellValue = ExcelFileUtil.getCellValue(row.getCell(3));
                    if (ExcelFileUtil.getCellValue(row.getCell(3)) != null && (!ExcelFileUtil.getCellValue(row.getCell(3)).equals(""))) {
                        eisdPo.setSystolic_ps(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setSystolic_ps((double) 0);
                    }
                    break;
                }
                case "Diastolic PS": {
                    if (ExcelFileUtil.getCellValue(row.getCell(3)) != null && (!ExcelFileUtil.getCellValue(row.getCell(3)).equals(""))) {
                        eisdPo.setDiastolic_ps(Double.valueOf((String) ExcelFileUtil.getCellValue(row.getCell(3))));
                    } else {
                        eisdPo.setDiastolic_ps((double) 0);
                    }
                    break;
                }

                case "sudomotor response（SMR）analysis":
                case "排汗反应（SMR）分析（足部皮肤微循环评分）":
                    resultMap.put("排汗反应（SMR）分析（足部皮肤微循环评分）", row.getRowNum());
                    break;

                case "notes of early diabetes risk and complication":
                case "糖尿病早期风险及并发症小知识":
                    resultMap.put("糖尿病早期风险及并发症小知识", row.getRowNum());
                    break;

                case "doctor’s advice":
                case "医生建议":
                    resultMap.put("doctor_advise", row.getRowNum());
                    break;

                case "自主神经系统功能障碍":
                    resultMap.put(attr, row.getRowNum());
                    break; //新版才有

                default: {
                    // logger.warn(attr+":字段不能同步，确认版本是否有误");
                }
                break;


            }
        }


        //获取医生建议
        int docAdRowNum = (int) resultMap.get("doctor_advise");
        String doctor_advise = ExcelFileUtil.getResult(sheet, docAdRowNum + 1, 0);
        eisdPo.setDoctor_advise(doctor_advise);

        //获取5个积分
        if (resultMap.get("排汗功能障碍评分") != null) {
            Cell phTotal = sheet.getRow((int) resultMap.get("排汗功能障碍评分") + 4).getCell(1);
            eisdPo.setSmr_total_score((String) ExcelFileUtil.getCellValue(phTotal));
        }

        if (resultMap.get("自主神经系统活性评分") != null) {
            Cell zjhxTotal = sheet.getRow((int) resultMap.get("自主神经系统活性评分") + 4).getCell(1);
            eisdPo.setAns_reactive_total_socre((String) ExcelFileUtil.getCellValue(zjhxTotal));
        }

        if (resultMap.get("自主神经系统平衡评分") != null) {
            Cell zjphTotal = sheet.getRow((int) resultMap.get("自主神经系统平衡评分") + 4).getCell(1);
            eisdPo.setAns_balance_total_socre((String) ExcelFileUtil.getCellValue(zjphTotal));
        }


        if (resultMap.get("内皮检测评分") != null) {
            Cell npTotal = sheet.getRow((int) resultMap.get("内皮检测评分") + 4).getCell(1);
            eisdPo.setEndo_dys_total_score((String) ExcelFileUtil.getCellValue(npTotal));
        }

        if (resultMap.get("内稳态评分") != null) {
            Cell nwtTotal = sheet.getRow((int) resultMap.get("内稳态评分") + 4).getCell(1);
            eisdPo.setPpg_total_score((String) ExcelFileUtil.getCellValue(nwtTotal));
        }

        //获取检测结果总结
        int ANSDRowNum = (int) resultMap.get("ansd");
        int SudoDRowNum = (int) resultMap.get("sudod");
        int EndoDRowNum = (int) resultMap.get("endod");
        int CMRRowNum = (int) resultMap.get("cmr");
        int IGTRowNum = (int) resultMap.get("igt");
        int PDNRowNum = (int) resultMap.get("pdn");
        int CADRowNum = (int) resultMap.get("cad");
        String PDNResult = null;
        String CANResult = null;
        if (resultMap.get("can") != null) {
            int CANRowNum = (int) resultMap.get("can");
            PDNResult = ExcelFileUtil.getResult(sheet, PDNRowNum, CANRowNum, 1);
            CANResult = ExcelFileUtil.getResult(sheet, CANRowNum, CADRowNum, 1);
        } else {
            PDNResult = ExcelFileUtil.getResult(sheet, PDNRowNum, CADRowNum, 1);
        }


        if (resultMap.get("排汗反应（SMR）分析（足部皮肤微循环评分）") != null) {
            int CADEndRowNum = (int) resultMap.get("排汗反应（SMR）分析（足部皮肤微循环评分）");
            String CADResult = ExcelFileUtil.getResult(sheet, CADRowNum, CADEndRowNum, 1);
            eisdPo.setCad(CADResult);//旧版本cad结果
        }
        if (eisdPo.getCad() == null) {
            int cadEndRowNum = (int) resultMap.get("自主神经系统功能障碍");
            String CADResult = ExcelFileUtil.getResult(sheet, CADRowNum, cadEndRowNum, 1);
            eisdPo.setCad(CADResult);//新版本cad结果
        }


        String ANSDResult = ExcelFileUtil.getResult(sheet, ANSDRowNum, SudoDRowNum, 1);
        String SudoDResult = ExcelFileUtil.getResult(sheet, SudoDRowNum, EndoDRowNum, 1);
        String EndoDResult = ExcelFileUtil.getResult(sheet, EndoDRowNum, CMRRowNum, 1);
        String CMRResult = ExcelFileUtil.getResult(sheet, CMRRowNum, IGTRowNum, 1);
        String IGTResult = ExcelFileUtil.getResult(sheet, IGTRowNum, PDNRowNum, 1);
        //String PDNResult=ExcelFileUtil.getResult(sheet,PDNRowNum,CANRowNum,1);
        //String CANResult=ExcelFileUtil.getResult(sheet,CANRowNum,CADRowNum,1);


        eisdPo.setAnsd(ANSDResult);
        eisdPo.setSudod(SudoDResult);
        eisdPo.setEndod(EndoDResult);
        eisdPo.setCmr(CMRResult);
        eisdPo.setIgt(IGTResult);
        eisdPo.setPdn(PDNResult);
        eisdPo.setCan(CANResult);


        //获取排汗解释
        if (resultMap.get("排汗解释") != null && resultMap.get("排汗功能障碍评分") != null) {
            int phStartRowNum = (int) resultMap.get("排汗解释") + 1;
            int phEndRowNum = (int) resultMap.get("排汗功能障碍评分");
            String phResult = ExcelFileUtil.getResult(sheet, phStartRowNum, phEndRowNum, 0);
            eisdPo.setPerspire_explanation(phResult);
        }

         //判断服务器是否存在相同paientId的记录，有则不上传
        JSONObject jsObject = new JSONObject();
        jsObject.put("patientId",eisdPo.getPatient_id());
        JSONObject existObj = HttpRequestUtils.httpPost(getbyPatIdURL, jsObject);
        int mark=-1;
       if(existObj!=null){
           int isExist = (int) existObj.get("mark");
           if(isExist==1||isExist==2){
               mark=0;
           }else {
               JsonConfig jsonConfig = new JsonConfig();
               jsonConfig.registerDefaultValueProcessor(Date.class, new DefaultValueProcessor() {
                   @Override
                   public Object getDefaultValue(Class aClass) {
                       return "";
                   }
               });
               jsonConfig.registerDefaultValueProcessor(Double.class, new DefaultValueProcessor() {
                   @Override
                   public Object getDefaultValue(Class aClass) {
                       return "";
                   }
               });
               jsonConfig.registerJsonValueProcessor(Integer.class, new JsonDateValueProcessor());
               JSONObject jsonObject = JSONObject.fromObject(eisdPo, jsonConfig);
               JSONObject resultObj = HttpRequestUtils.httpPost(uploadURL, jsonObject);
               if(resultObj==null){
                   mark=-1;
               }else {
                   mark = resultObj.getInt("mark");
               }
           }
       }
        return mark;

    }


}
